import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { SMiniGuildInfo } from "../../../../../Message/Game/SMiniGuildInfo";
import { GuildConfig } from "../../../resource/GuildConfig";
import { GuildUtil } from "../info/GuildUtil";
import { Language } from "../../../../../extend/language/Language";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GameDefConfig } from "../../../resource/GameDefConfig";
import { ColorConfig } from "../../../resource/ColorConfig";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { SPlayerGuildInfo } from "../../../../../Message/Game/SPlayerGuildInfo";
import { SMoney } from "../../../../../Message/Game/SMoney";
import { Cache } from "../../../cache/Cache";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GameConst } from "../../../../component/gconst/GameConst";
import { MsgManager } from "../../../manager/MsgManager";
import { EEntityFightMode } from "../../../../../Message/Public/EEntityFightMode";
import { Alert } from "../../../../../com/mui/controls/Alert";
type int = number;
//class ManorRender
    
    export  class ManorRender extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=0;
            super.data = arg1;
            this._sMiniGuildInfo = arg1 as SMiniGuildInfo;
            if (this._sMiniGuildInfo) 
            {
                loc1 = GuildConfig.instance.getMaxNumByLevel(this._sMiniGuildInfo.level) + GuildUtil.getRoomNumByLevel(this._sMiniGuildInfo.house);
                if (this._sMiniGuildInfo.haveSpace) 
                {
                    this._manor = Language.getString(57118);
                }
                else 
                {
                    this._manor = "";
                }
                this.nameTxt.htmlText = this._sMiniGuildInfo.guildName + this._manor;
                this.campTxt.htmlText = HTMLUtil.addColor(GameDefConfig.instance.getECamp(this._sMiniGuildInfo.camp), ColorConfig.instance.getCampColor(this._sMiniGuildInfo.camp).color);
                this.chairmanTxt.text = this._sMiniGuildInfo.leaderName;
                this.levelTxt.text = this._sMiniGuildInfo.level.toString();
                this.numberTxt.text = this._sMiniGuildInfo.playerNum.toString() + "/" + loc1.toString();
            }
            return;
        }

        /* internal  */init(): void
        {
            var loc1=11661567;
            this.nameTxt = new Object /* flash.text.TextField */();
            this.nameTxt.x = 10;
            this.nameTxt.y = 0;
            this.nameTxt.height = 30;
            this.nameTxt.selectable = false;
            this.nameTxt.textColor = loc1;
            this.nameTxt.width = 100;
            this.nameTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            addChild(this.nameTxt);
            this.campTxt = new Object /* flash.text.TextField */();
            this.campTxt.x = 130;
            this.campTxt.y = 0;
            this.campTxt.height = 30;
            this.campTxt.selectable = false;
            this.campTxt.textColor = loc1;
            this.campTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            addChild(this.campTxt);
            this.chairmanTxt = new Object /* flash.text.TextField */();
            this.chairmanTxt.x = 155;
            this.chairmanTxt.y = 0;
            this.chairmanTxt.height = 30;
            this.chairmanTxt.selectable = false;
            this.chairmanTxt.textColor = loc1;
            this.chairmanTxt.width = 115;
            this.chairmanTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            addChild(this.chairmanTxt);
            this.levelTxt = new Object /* flash.text.TextField */();
            this.levelTxt.x = 300;
            this.levelTxt.y = 0;
            this.levelTxt.height = 30;
            this.levelTxt.width = 50;
            this.levelTxt.selectable = false;
            this.levelTxt.textColor = loc1;
            this.levelTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            addChild(this.levelTxt);
            this.numberTxt = new Object /* flash.text.TextField */();
            this.numberTxt.x = 365;
            this.numberTxt.y = 0;
            this.numberTxt.height = 30;
            this.numberTxt.width = 70;
            this.numberTxt.selectable = false;
            this.numberTxt.textColor = loc1;
            this.numberTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            addChild(this.numberTxt);
            this.enterIngBtn = new GButton();
            this.enterIngBtn.label = Language.getString(57119);
            this.enterIngBtn.styleName = "Button";
            this.enterIngBtn.setSize(67, 24);
            this.enterIngBtn.move(445, 0);
            this.enterIngBtn.drawNow();
            this.enterIngBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onEnterInBtnClickHandler);
            addChild(this.enterIngBtn);
            ObjCreate.createBg(10, 25, 523, 2, this, ImagesConst.SplitLine);
            return;
        }

        /* internal  */onEnterInBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            var e: Object /* flash.events.Event */;
            var toGuildId: int;
            var myGuild: SPlayerGuildInfo;
            var money: SMoney;
            var content: string;
            var closeAlert: Function;

            var loc1;
            toGuildId = 0;
            money = null;
            content = null;
            e = arg1;
            toGuildId = this._sMiniGuildInfo.guildId;
            myGuild = Cache.instance.guild.myGuildInfo;
            if (myGuild && toGuildId == myGuild.guildId) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildEnterManor, {"guildId": toGuildId, "useContribution": false}));
            }
            else 
            {
                if (Cache.instance.role.entityInfo.level < GameConst.SetFightModeLevel) 
                {
                    MsgManager.showRollTipsMsg(Language.getStringByParam(57120, GameConst.SetFightModeLevel));
                    return;
                }
                money = Cache.instance.role.money;
                if (money.coinBind + money.coin < 200) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(57121));
                    return;
                }
                if (!(Cache.instance.role.entityInfo.camp == this._sMiniGuildInfo.camp) && Cache.instance.role.entityInfo.fightModel == EEntityFightMode._EEntityFightModePeace) 
                {
                    closeAlert = (arg1: int): void
                    {
                        if (arg1 == Alert.OK) 
                        {
                            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildEnterManor, {"guildId": toGuildId, "useContribution": false}));
                        }
                        return;
                    }
                    content = Language.getString(57122);
                    Alert.show(content, null, Alert.OK | Alert.CANCEL, null, closeAlert);
                }
                else 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildEnterManor, {"guildId": toGuildId, "useContribution": false}));
                }
            }
            return;
        }

        /* internal */ /* var */nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */campTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */chairmanTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */levelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */numberTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */enterIngBtn: GButton;

        /* internal */ /* var */_sMiniGuildInfo: SMiniGuildInfo;

        /* internal */ /* var */_manor: string="";
    }
